﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using V5_Model;
using V5_BLL;
using V5_Common;

namespace V5_EShop._Template.Default
{
    public partial class product_list : BasicPage
    {
        public ModelProductClass productclass = new ModelProductClass();
        public int _classid = 0, _showid = 0, _orderid = 0, _pageid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                _classid = Input.SetInt(Request["classid"]);
                _showid = Input.SetInt(Request["showid"]);
                if (_showid == 0)
                {
                    _showid = 1;
                }
                _orderid = Input.SetInt(Request["orderid"]);
                _pageid = Input.SetInt(Request["pageid"]);
                if (_pageid == 0)
                {
                    _pageid = 1;
                }
                this.Bind_rpList();
                if (_classid > 0)
                {
                    productclass = new BLLProductClass().GetModel(_classid);
                }
            }
        }

        private void Bind_rpList()
        {
            string PageUrl = "/product-list-[1]-[2]-[3]-{0}." + config.UrlRewrite;
            int count = 0;
            string strWhere = "";
            Pager.CurrentPageIndex = _pageid;
            //开始过滤参数
            if (_classid > 0)
            {
                strWhere += " ClassID=" + _classid;
            }
            switch (_showid)
            {
                case 1:
                    Pager.PageSize = 12;
                    break;
                case 2:
                    Pager.PageSize = 6;
                    break;
            }
            DataTable dt = new BLLProduct().GetList(Pager.PageSize, Pager.CurrentPageIndex, strWhere, ref count).Tables[0];
            this.Pager.RecordCount = count;

            PageUrl = PageUrl.Replace("[1]", _classid.ToString()).
                            Replace("[2]", _showid.ToString()).
                            Replace("[3]", _orderid.ToString());
            this.Pager.UrlRewritePattern = PageUrl;
            switch (_showid)
            {
                case 1:
                    Bind_rpList1(dt);
                    break;
                case 2:
                    Bind_rpList2(dt);
                    break;
            }
        }


        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            Bind_rpList();
        }

        private void Bind_rpList1(DataTable dt)
        {
            this.rpList1.Visible = true;
            this.rpList2.Visible = false;
            this.rpList1.DataSource = dt;
            this.rpList1.DataBind();
        }

        private void Bind_rpList2(DataTable dt)
        {
            this.rpList2.Visible = true;
            this.rpList1.Visible = false;
            this.rpList2.DataSource = dt;
            this.rpList2.DataBind();
        }
    }
}
